﻿using System.Windows.Controls;
using WPFTestSolution.Bean;

namespace WPFTestSolution.Pages.Controls.ItemsControls.ListBoxes {
    
    /**
     * https://www.bilibili.com/video/BV1bV411A7Eq?p=54
     * 054-ListView数据列表控件(: ListBox)
     * https://www.wpfsoft.com/2023/09/06/1805.html
     */
    public partial class _54ListView_Page : Page {
        public _54ListView_Page() {
            InitializeComponent();
            this.Title = "054-ListView数据列表控件(: ListBox)";
            
            this.listview.Items.Add(new Person { Name = "张三", Age = 22, Address = "广东省廉江市车板镇大坝村" });
            this.listview.Items.Add(new Person { Name = "李四", Age = 23, Address = "江西省景德镇市市辖区" });
            this.listview.Items.Add(new Person { Name = "王五", Age = 24, Address = "上海市虹口区" });
        }

        private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            if (!(sender is ListView listView)) return;

            if (!(listView.SelectedItem is Person person)) return;
 
            _TextBlock.Text = $"姓名: {person.Name}, 年龄: {person.Age}, 地址: {person.Address}";
        }
    }
}